package wisents.wicket.element;

import wisents.api.ElementCriteria;
import wisents.api.PageElement;
import wisents.api.factory.Vendor;
import wisents.wicket.WicketPageElement;
import wisents.wicket.WicketVendor;
import org.apache.wicket.util.tester.WicketTester;
import pl.rabbitsoftware.EnhancedWicketTester;

/**
 * User: paul.szulc
 * Date: Jan 11, 2010
 * Time: 10:43:32 PM
 */
abstract class AbstractWicketElementCriteria implements ElementCriteria {

    protected WicketPageElement pageElement;

    protected WicketTester tester;
    protected EnhancedWicketTester enhancedTester;

    protected AbstractWicketElementCriteria(PageElement pageElement) {   	
    	addPageElement(pageElement);
    	addTesters();
    }
    
    private void addPageElement(PageElement pageElement) {
    	
    	if(pageElement instanceof WicketPageElement) {
            this.pageElement = (WicketPageElement)pageElement;
    	} else {
    		throw new IllegalArgumentException("WicketPageElement type is needed");
    	}
    }
    
    private void addTesters() {
        WicketVendor wicketVendor = (WicketVendor) Vendor.getInstance();
        tester = wicketVendor.getTester();
        enhancedTester = wicketVendor.getEnhancedTester();
    }
}
